<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+


class SettingParser extends SettingParserCommon
{		

	function parseIn($key, $value) {
		
		if($key == 'file_dir') {
			$value = $value . '/';
			$pattern = array();
			$pattern[] = '#\\\\#';
			$pattern[] = '#/{2,}#';
			
			$value = preg_replace($pattern, '/', $value);
		
		} elseif($key == 'file_denied_extensions') {
			$value = str_replace(array(' ', '  '), '', $value);
		
		} elseif($key == 'file_allowed_extensions') {
			$value = str_replace(array(' ', '  '), '', $value);
		
		// set max size nor more than upload_max_filesize
		} elseif($key == 'file_max_filesize') {
		
			// upload_max_filesize "2M" PHP_INI_SYSTEM|PHP_INI_PERDIR 
			$size = ini_get('upload_max_filesize')*1024;
			$value = ($value > $size) ? $size : $value; 
		}
		
		return $value;
	}
	
	
	function parseOut($key, $value) {
	
		if(APP_DEMO_MODE && $key == 'file_dir') {
			$value = '- - - - - - - - - - -';
		}
	
		return $value;
	}
	
	
	// when display
	function skipSettingDisplay($key, $value = false) {
		$ret = false;
		$files_settings = array('show_num_entries',
								'category_sort_order',
								'num_entries_per_page',
								'num_recently_posted_entries',
								'num_most_viewed_entries',
								'num_category_cols',
								'private_policy',
								'file_extract');
		
		if(in_array($key, $files_settings) && !$this->model->isExtra('file')) {
			$ret = true;
		
		} elseif($key == 'private_policy' && !$this->model->isExtra('private')) {
			$ret = true;
		}
		
		
		
		return $ret;
	}	
}
?>
